#include "PlayerStateTakeDamage.h"
#include "Player.h"
#include "GameTime.h"

PlayerStateTakeDamage::PlayerStateTakeDamage(Player* player) : PlayerState(player)
{
}


PlayerStateTakeDamage::~PlayerStateTakeDamage(void)
{
}

void PlayerStateTakeDamage::activate()
{
	_player->removeFlag(TAKE_DAMAGE);
	_player->getAnimationMgr().setAnimation("take_damage");
	_player->_velocity.y = -(150.0f * GameTime::getSingleton()->deltaTime());
	_direction = _player->getFlip();
	_player->_onGround = false;
	_player->setFlipChangeAllow(false);
	_player->setFlag(GRAVITY_AFFECTED);
	_player->resetDash();
}

void PlayerStateTakeDamage::deactivate()
{
	_player->startFlashing();
	_player->setFlipChangeAllow(true);
}

int PlayerStateTakeDamage::update()
{
	_player->_velocity.x = -(((_player->getSpeed()) * GameTime::getSingleton()->deltaTime()) * _direction);

	if (_player->_onGround)
	{
		return PSRV_IDLE;
	}

	return PSRV_NOTHING;
}